<template>
  <div>
      <div id="editor"></div>
  </div>
</template>

<script>
import E from "wangeditor";
export default {
    props: {
        editorContent:{}
    },
    data() {
        return {
            editor:"",
            info_:null
        }
    },
    created() {

    },
    mounted() {
        this.cRichText();
    },
    methods: {
        // 创建富文本
        cRichText() {
            this.editor = new E("#editor");
            this.editor.config.uploadImgHeaders = {
                token:localStorage.getItem('token')
            }
            // 配置接收这个文件的字段
            this.editor.config.uploadFileName = 'file'
            this.editor.config.uploadVideoName = 'file'
            this.editor.config.uploadImgAccept = ['jpg', 'jpeg', 'png', 'gif']		
            if(process.env.NODE_ENV == 'development'){
                this.editor.config.uploadImgServer = `http://localhost:8081/api/admin/index/uploadFile?type=0`
                this.editor.config.uploadVideoServer = `http://localhost:8081/api/admin/index/uploadFile?type=1`
            }else{
            	// 如果使用了代理，这里最好填写完整的api地址
                this.editor.config.uploadImgServer = '/admin/index/uploadFile?type=0'
                this.editor.config.uploadVideoServer = '/admin/index/uploadFile?type=1'
            }
            // 图片
            this.editor.config.uploadImgHooks = {
                // 图片上传并返回了结果，想要自己把图片插入到编辑器中
                customInsert: function(insertImgFn, result) {
                    // insertImgFn 可把图片插入到编辑器，传入图片 src ，执行函数即可
                    insertImgFn(result.data.url)
                }
            }

            this.editor.config.onchange=(html)=>{
          　　　 this.$emit("change",html)
        　　}
            this.editor.create()
            this.editor.txt.html(this.editorContent.notice_content);
        },
    }
}
</script>

<style lang="scss" scoped>

</style>